package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.mapper.UserMapper;
import com.itheima.health.pojo.Permission;
import com.itheima.health.pojo.User;
import com.itheima.health.service.UserService;
import com.itheima.health.vo.RoleVO;
import com.itheima.health.vo.UserVO;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

@Service
@Transactional
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Override
    public UserVO findUserDetailsByUsername(String username) {
        //1.根据用户名查找用户详细信息       t_user
        UserVO userVO = baseMapper.findUserByUsername(username);
        //2.根据根据用户id查找角色信息 --keyword   t_role_user,t_role
        List<RoleVO> roleVOSet = baseMapper.findRolesByUserId(userVO.getId());
        userVO.setRoles(roleVOSet);
        //3.根据角色id查找对应的权限信息  ---keyword     t_role_permission,t_permission
        for (RoleVO roleVO : roleVOSet) {
            List<Permission> permissionSet = baseMapper.findPermissionByRid(roleVO.getId());
            roleVO.setPermissionList(permissionSet);
        }

        return userVO;
    }


}
